<?php // dbObject.php

class dbObject {
	public $dbTable;
	public $tableKey;
	public $keyType;
	public $expire;
	
	public $members;
	public $value;
	
	public function getColumns() {
		$columns = array();
		foreach($this as $key => $value) {
			if ($key != 'dbTable' && $key != 'tableKey' && $key != 'keyType') $columns[] = $key;
		}
		return $columns;
	}

	public function find($keyValue) {
		$redis = Database::connect();
		
		$tkey = $this->dbTable . ':' . $keyValue;
		if ($this->keyType == 'hash') {
			foreach ($redis->hGetAll($tkey) as $key => $val) {
				$this->$key = $val;
			}
		} else if ($this->keyType == 'string') {
			$this->value = $redis->get($tkey);
			
		} else if ($this->keyType == 'set') {
			$this->members = $redis->sMembers($tkey);
			
		} else if ($this->keyType == 'list') {
			$this->members = $redis->lRange($tkey, 0, 10000);
			
		}
		
		return $this;
	}
	
	// insert database record
	public function insert() {
		return Database::insert($this);
	}

	// update database record
	public function update() {
		return Database::update($this);
	}
	
}

?>